{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 字典的遍历"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## `.keys()`\n",
    "\n",
    "- `.key()` 方法会返回一个序列，序列中保存有字典所有的 `key`"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "issac = {'name':'Issac','age':18,'gender':'boy'}\n",
    "print(f'issac.keys() = {issac.keys()}, type(issac.keys()) = {type(issac.keys())}')\n",
    "\n",
    "i = 1\n",
    "for key in issac.keys():\n",
    "    print(f'key_{i} = {key}')\n",
    "    print(f\"issac['{key}'] = {issac[key]}\\n\")\n",
    "    i += 1"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## `.values()`\n",
    "\n",
    "- `.values()` 方法会返回一个序列，序列中保存有字典所有的 `value`"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "issac = {'name':'Issac','age':18,'gender':'boy'}\n",
    "print(f'issac.keys() = {issac.keys()}, type(issac.keys()) = {type(issac.keys())}')\n",
    "\n",
    "i = 1\n",
    "for value in issac.values():\n",
    "    print(f'value_{i} = {value}')\n",
    "    i += 1"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## `items()`\n",
    "\n",
    "- `items()` 方法会返回字典中所有的项\n",
    "- 它会返回一个序列，包含双值子序列\n",
    "- 双值分别是字典中的 `key` 和 `value`"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "issac = {'name':'Issac','age':18,'gender':'boy'}\n",
    "print(f'issac.items() = {issac.items()}')\n",
    "\n",
    "i = 1\n",
    "for key,value in issac.items():\n",
    "    print(f'key_{i} = {key}')\n",
    "    print(f'value_{i} = {value}')\n",
    "    print(f\"issac['{key}'] = {value}\\n\")\n",
    "    i += 1"
   ]
  }
 ],
 "metadata": {
  "interpreter": {
   "hash": "767d51c1340bd893661ea55ea3124f6de3c7a262a8b4abca0554b478b1e2ff90"
  },
  "kernelspec": {
   "display_name": "Python 3.9.5 64-bit",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.5"
  },
  "orig_nbformat": 2
 },
 "nbformat": 4,
 "nbformat_minor": 2
}